home *** CD-ROM | disk | FTP | other *** search
/ Amiga Collections: Taifun / Taifun 099 (1989-05-15)(Ossowski, Stefan)(DE)(PD).zip / Taifun 099 (1989-05-15)(Ossowski, Stefan)(DE)(PD).adf / PCQ / Examples / Nests.p < prev    next >
Text File  |  1989-03-31  |  1KB  |  50 lines

  1. program Nests;
  2.  
  3.     { This program demonstrates that, to some extent, nested
  4.       procedures do seem to work.  The compiler will accept them
  5.       just fine, but does not always produce the right code.  The
  6.       only problems, as mentioned in the docs, are that 1) you
  7.       might end up with duplicate ID's in the assembly output, and
  8.       2) when you try to access a local variable of a parent
  9.       procedure or function, the compiler gets the proper offset,
  10.       but uses the activation frame of the current procedure, rather
  11.       than its parent, as it should. }
  12.  
  13. var
  14.     first : Integer;
  15.  
  16. procedure outermost;
  17. var
  18.    first : char;
  19.  
  20.     procedure inner;
  21.     var
  22.     first : short;
  23.  
  24.     procedure innermost;
  25.     var
  26.         first : integer;
  27.     begin
  28.         first := 42;
  29.         writeln('In innermost, first = ', first);
  30.     end;
  31.  
  32.     begin
  33.     first := 67;
  34.     innermost;
  35.     writeln('In inner, first = ', first);
  36.     end;
  37.  
  38. begin
  39.     first := 'r';
  40.     inner;
  41.     writeln('In outermost, first = ', first);
  42. end;
  43.  
  44. begin
  45.     first := 78;
  46.     outermost;
  47.     writeln('In main program, first is ', first);
  48. end.
  49.  
  50.